﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System .Data ;
using System .Data .SqlClient ;
using dhDataAcess.orderLinqDAL ;

namespace dhDataAcess.orderDAL
{
  public   class pbomDetailDAL
    {
      string tableName = "pbomDetail";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public pbomDetailDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入产品BOM从表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pbomDetailInsert(pbomDetailModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                    new SqlParameter ("@mark",row .mark ),
                                    new SqlParameter ("@aweight",row .aweight),
                                    new SqlParameter ("@alen",row .alen ),
                                    new SqlParameter ("@pweight",row .pweight ),
                                    new SqlParameter ("@blen",row .blen ),
                                    new SqlParameter ("@ts",row .ts ),
                                    new SqlParameter ("@pz",row .pz ),
                                    new SqlParameter ("@pt",row .pt ),
                                    new SqlParameter ("@matNum",row .matNum),
                                    new SqlParameter ("@wb",row .wb ),
                                    new SqlParameter ("@pname",row .pname ),
                                     new SqlParameter ("@matName",row .matName  ),
                                     new SqlParameter ("@Series",row.Series   )
                                  };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新产品BOM从表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pbomDetailUpdate(pbomDetailModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                    new SqlParameter ("@recordid",row .recordid ),
                                    new SqlParameter ("@mark",row .mark ),
                                    new SqlParameter ("@aweight",row .aweight),
                                    new SqlParameter ("@alen",row .alen ),
                                    new SqlParameter ("@pweight",row .pweight ),
                                    new SqlParameter ("@blen",row .blen ),
                                    new SqlParameter ("@ts",row .ts ),
                                    new SqlParameter ("@pz",row .pz ),
                                    new SqlParameter ("@pt",row .pt ),
                                    new SqlParameter ("@matNum",row .matNum),
                                    new SqlParameter ("@wb",row .wb ),
                                    new SqlParameter ("@pname",row .pname ),
                                    new SqlParameter ("@matName",row .matName  ),
                                     new SqlParameter ("@Series",row.Series   )
                                  };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行产品BOM从表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pbomDetailDel(string recordid)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr (tableName).ToString();
            SqlParameter[] para = {
                                 
                                    new SqlParameter ("@recordid",recordid),
                                 
                                  };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr ;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行产品BOM从表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int pbomDetailDelALL(string pname)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = "delete pbomDetail where pname =@pname";
            SqlParameter[] para = {
                                 
                                    new SqlParameter ("@pname",pname),
                                 
                                  };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
